﻿using Assets.Scripts.System;
using System.Collections;
using UnityEngine;


public class Chest1 : MonoBehaviour, IInteractable
{
    public Animator animator;
    private void Awake()
    {
        animator = GetComponent<Animator>();
    }
    public void ChangeBeforeInteracte()
    {

    }

    public void Interacte(GameObject trigger)
    {
        if(trigger.CompareTag("Player"))
        {
            animator.SetTrigger("IsOpen");
            AttributeData data = PlayerSystem.Instance.GetAttrData();
            // TODO:随机附加一个效果，以后根据分配系统改
            int randomValue = Random.Range(0, 6);
            switch (randomValue)
            {
                case 0:
                    trigger.GetComponent<HealthControllerBase>().Recover(50);
                    Debug.Log($"得到效果：恢复50生命");
                    break;
                case 1:
                    trigger.GetComponent<HealthControllerBase>().Hit(20);
                    Debug.Log($"得到效果：受到20伤害");
                    break;
                case 2:
                    data.AttackSpeed += 1000;
                    Debug.Log($"得到效果：攻击速度提高1000");
                    break;
                case 3:
                    data.MoveSpeedScale *= 1.5f;
                    Debug.Log($"得到效果：移动速度提高0.5倍");
                    break;
                case 4:
                    data.CritRate += 0.1f;
                    Debug.Log($"得到效果：暴击率提高10%");
                    break;
                case 5:
                    data.ReloadReduction += 100;
                    Debug.Log($"得到效果：换弹速度提高100");
                    break;
                default:
                    break;
            }
            GetComponent<BoxCollider2D>().enabled = false;
        }
    }
    public void ChangeAfterInteracte()
    {

    }
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            collision.gameObject.GetComponent<PlayerController>().AddInteractObject(this);
        }
    }
    private void OnCollisionExit2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            collision.gameObject.GetComponent<PlayerController>().RemoveInteractObject(this);
        }
    }
}
